package com.mflex.WHSmartWhouseAd.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mflex.WHSmartWhouseAd.R;
import com.mflex.WHSmartWhouseAd.model.MaterialDetailForDelisModel;
import com.mflex.WHSmartWhouseAd.model.WHDelisTaskDetailModel;
import com.xuexiang.xutil.common.StringUtils;

import java.util.List;

public class WMSOutStockTaskDetailAdapter extends BaseAdapter {
    List<MaterialDetailForDelisModel> items;
    Activity context;

    public WMSOutStockTaskDetailAdapter(Activity context, List<MaterialDetailForDelisModel> items) {
        this.context = context;
        this.items = items;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MaterialDetailForDelisModel item = items.get(position);
        View view = convertView;
        view = context.getLayoutInflater().inflate(R.layout.item_wms_outstock_task_detail_list, null);
        ((TextView) view.findViewById(R.id.txtPN)).setText(item.getMaterialPart());
        ((TextView) view.findViewById(R.id.txtLoc)).setText(item.getWHLocation());
        ((TextView) view.findViewById(R.id.txtVehicleNO)).setText(item.getVehicleNumber());
        ((TextView) view.findViewById(R.id.txtQty)).setText(item.getQty());
        ((TextView) view.findViewById(R.id.txtScanQty)).setText(item.getScanQty());
        ((TextView) view.findViewById(R.id.txtflg)).setText(item.getflg());


        if (StringUtils.equals("1",item.getflg())) {
            ((LinearLayout) view.findViewById(R.id.txtList)).setBackgroundColor(Color.YELLOW);
        }
        if (StringUtils.equals("2",item.getflg())) {
            ((LinearLayout) view.findViewById(R.id.txtList)).setBackgroundColor(Color.GREEN);
        }

        return view;
    }
}